package com.db;

import java.util.concurrent.ConcurrentHashMap;

import org.slf4j.ILoggerFactory;
import org.slf4j.Logger;

public class LoggerFactory implements ILoggerFactory {
	private static final ConcurrentHashMap<String, Logger> loggers = new ConcurrentHashMap<String, Logger>();

	public Logger getLogger(String name) {
		final Logger logger = loggers.get(name);
		if (logger != null) {
			return logger;
		}
		
		final MyLogger newLogger = new MyLogger(name);
		final Logger oldValue = loggers.putIfAbsent(name, newLogger);
		return oldValue == null ? newLogger : oldValue;
	}
	public Logger getLogger(String name, LevelLogger level) {
		final Logger logger = loggers.get(name);
		if (logger != null) {
			return logger;
		}
		
		final MyLogger newLogger = new MyLogger(name, level);
		final Logger oldValue = loggers.putIfAbsent(name, newLogger);
		return oldValue == null ? newLogger : oldValue;
	}
}
